package cn.wk.libs4a.view;

import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import cn.wk.libs4a.R;
import cn.wk.libs4a.WKBaseActivity;

/**
 * Web页面
 */
public class WKWebAct extends WKBaseActivity {

	private String url = "";
	private String title = "";

	public static Share share;

	@Override
	public void loadXml() {
		setContentView(R.layout.wk_act_webview);
	}

	@Override
	public void init() {
		getHeader().setRightTxt("分享");
		getHeader().setClickListener(null, null, new OnClickListener() {
			public void onClick(View arg0) {
				try {
					share.share(title, url, title);
				} catch (Exception e) {
				}
			}
		});

		url = getIntent().getStringExtra("url");
		title = getIntent().getStringExtra("title");
		if (title != null) {
			getHeader().setTitle(title);
		}

		WebView webView = (WebView) super.findViewById(R.id.ad_webview);
		// 清理webview缓存
		webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		webView.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				// 设置点击网页里面的链接还是在当前的webview里跳转
				view.loadUrl(url);
				return true;
			}
		});
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl(url.startsWith("http") ? url : "http://" + url);
	}

	@Override
	public void setData() {
	}

	public interface Share {
		public void share(String title, String url, String txt);
	}

}
